package com.yyk.yiliao.ui.trade.minepwd;

import android.view.View;
import android.widget.RelativeLayout;

import com.orhanobut.logger.Logger;
import com.yyk.yiliao.R;
import com.yyk.yiliao.base.BaseActivity;
import com.yyk.yiliao.ui.trade.InvestPasswordActivity;
import com.yyk.yiliao.util.DialogUtil;
import com.yyk.yiliao.util.Md5Util2;
import com.yyk.yiliao.util.rx.ApiService;
import com.yyk.yiliao.util.rx.RxUtils;
import com.yyk.yiliao.bean.UserbankSetuppwdInfo;

import java.util.Map;
import java.util.TreeMap;

import butterknife.BindView;
import butterknife.OnClick;
import rx.Subscriber;
import rx.android.schedulers.AndroidSchedulers;
import rx.schedulers.Schedulers;

/**
 * 安全设置
 */
public class SafeSetActivity extends BaseActivity {
    @BindView(R.id.rl_zhmm)
    RelativeLayout rlZhmm;
    @BindView(R.id.rl_jymm)
    RelativeLayout rlJymm;

    @Override
    public int getLayoutId() {
        return R.layout.activity_safe_set;
    }

    @Override
    public void initView() {
        initToolbar();

    }

    private void initToolbar() {

        setBackArrow();
        setTitle("安全设置");
    }

    @Override
    public void initData() {

    }


    /**
     * 1.账户密码
     * 2.交易密码
     *
     * @param view
     */
    @OnClick({R.id.rl_zhmm, R.id.rl_jymm})
    public void onViewClicked(View view) {
        switch (view.getId()) {
            case R.id.rl_zhmm:
                startAct(SetPasswordActivity.class);
                break;
            case R.id.rl_jymm:
                Map<String, String> map = new TreeMap<>();
                map.put("type_user", "1");
                map.put("id", "184");
                map.put("sign", Md5Util2.createSign(map));
                //如果有交易密码，跳转到修改密码，没有跳转到新增交易密码
                RxUtils.getInstance().retrofit.create(ApiService.class).postUserbankSetuppwd(map)
                        .subscribeOn(Schedulers.io())     //调度线程
                        .observeOn(AndroidSchedulers.mainThread())
                        .unsubscribeOn(Schedulers.io())   //取消订阅
                        .subscribe(new Subscriber<UserbankSetuppwdInfo>() {
                            @Override
                            public void onNext(UserbankSetuppwdInfo info) {
                                Logger.e("是否设置交易密码" + info.toString());
                                //1.已设置2.未设置
                                if (info.getCode() == 1) {
                                    startAct(SetInvestPasswordActivity.class);
                                } else if (info.getCode() == 2) {
                                    DialogUtil.getIntanse().simpleDialog(mActivity, "设置交易密码", "为了您的账户安全，请先设置交易密码", "确定", "取消", new DialogUtil.AlertDialogListenter() {
                                        @Override
                                        public void queding() {
                                            startAct(InvestPasswordActivity.class);
                                        }

                                        @Override
                                        public void quxiao() {

                                        }
                                    });
                                }
                            }

                            @Override
                            public void onCompleted() {
                            }

                            @Override
                            public void onError(Throwable e) {

                            }
                        });
                break;
        }
    }
}
